//
//  PrintPopWindow.m
//  mywork
//
//  Created by My Mac on 2018/4/23.
//  Copyright © 2018年 li. All rights reserved.
//

#import "PrintPopWindow.h"

@interface PrintPopWindow () <UITableViewDataSource, UITableViewDelegate,UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
//@property (weak, nonatomic) IBOutlet UIButton *xButton;

@end

@implementation PrintPopWindow

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self doInit];
}

- (void)doInit
{
    self.maxShowCells = 5;
    self.cellHeight = 44.0;
    self.tableView.bounces = NO;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.xButton addTarget:self action:@selector(onX:) forControlEvents:UIControlEventTouchUpInside];
    self.daYinButton.layer.cornerRadius = 7.0;
    _table = self.tableView;
}

- (void)setCells:(NSArray<UITableViewCell *> *)cells
{
    _cells = cells;
    self.heightConstraint.constant = self.maxShowCells * self.cellHeight;
    [_tableView reloadData];
}

- (void)onX:(id)sender
{
    [self removeFromSuperview];
    
    if (_closeBlock) {
        _closeBlock();
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cells.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.cells[indexPath.row];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.cellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.clickCell) {
        self.clickCell(self.cells[indexPath.row], indexPath.row);
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

}

@end
